package cn.lh.controller;

import cn.lh.config.Resp;
import cn.lh.entity.req.LoginReq;
import cn.lh.entity.vo.LoginInfoVo;
import cn.lh.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @描述:
 * @版权: Copyright (c): 2025
 * @作者: linhong
 * @创建日期: 2025/04/14
 */
@Api(tags = "登录")
@Validated
@Slf4j
@RestController
public class LoginController extends BaseController{

    @Resource
    private LoginService loginService;


    @ApiOperation(value = "登录", notes = "登录")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @PostMapping("/login")
    public Resp<LoginInfoVo> login(@RequestBody @Valid LoginReq req){
        LoginInfoVo login = loginService.login(req);
        return ok(login);
    }

    @ApiOperation(value = "退出", notes = "退出")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @PutMapping("/logout")
    public Resp<?> logout(@RequestHeader String token,@RequestParam String userName){
        loginService.logout(token, userName);
        return ok();
    }


}
